'use strict';
const axios = require("axios")
const Controller = require('egg').Controller;

class CollertionController extends Controller {
  async index() {
    const { ctx } = this;
    // console.log(ctx.request.body)
    var db = this.app.mongodb;
    var { val } = ctx.request.body
    console.log(val.id);
    var res = await db.collection("list").find({ id: val.id }).toArray()
    console.log(res);
    if (res.length) {
      ctx.body = {
        code: 400,
        msg: "已关注"
      }
    } else {
      var ent = await db.collection("list").insertOne(val)
      ctx.body = {
        code: 200,
        msg: "关注成功"
      }
    }
  }
}

module.exports = CollertionController;
